package org.wattdepot.cli.processor;

import java.util.List;
import org.wattdepot.cli.command.WattPower;

/**
 * Parses the power command.
 * 
 * @author Kendyll Doi
 * @author Kimberly Heu
 *
 */
public class PowerCommand extends CommandLineInterface implements WattDepotCliCommand {
  
  /**
   * Parses the power command.
   * 
   * @param args The user's inputed arguments.
   * @return The results of running the power command.
   */
  public String doCommand(List<String> args) {
    StringBuffer buf = new StringBuffer(500); // Buffer to store the results
    String output = ""; // String with contents to return
    
    // Check the number of arguments in the command
    if (args.size() == 5) {
      // Check the syntax of the arguments in the command
      if ((args.get(1).equalsIgnoreCase("generated") || args.get(1).equalsIgnoreCase("consumed"))
          && args.get(3).equalsIgnoreCase("timestamp")) {
        buf.append(WattPower.wattListPowerTime(args.get(1), args.get(2), args.get(4),
            client));
      }
      else {
        buf.append("Incorrect syntax for power command.");
      }
    }
    else {
      // Give an error message for the number of arguments
      buf.append("Incorrect number of arguments for power command.");
    }
    
    // Convert buffer to string and return
    output = buf.toString();
    return output;
  }
}
